import App from './App.vue'
import router from './router'
import stores from './store'
import globalStores from '@/store'
Vue.config.productionTip = false

/* 挂载全局和局部依赖 */
require('./register')

let app = null

function render(props = {}) {
  const { container } = props

  app = new Vue({
    router,
    store: globalStores(stores),
    render: h => h(App)
  }).$mount(container ? container.querySelector('#app') : '#app')
}

/* 独立运行时 */
if (!window.__POWERED_BY_QIANKUN__) {
  render()
} else {
  __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__
}

/* qiankun 抛出的生命周期 */
export async function bootstrap() {}
export async function mount(props) {
  Vue.prototype.$rootApp = props
  render(props)
}
export async function unmount() {
  app.$destroy()
  app.$el.innerHTML = ''
  app = null
}
